package com.vista.questionnaire.exception;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

public class ErrorDescriptorSerializer extends JsonSerializer<ErrorDescriptor> {

    private static final String KEY_CODE = "code";
    private static final String KEY_DESCRIPTION = "description";

    @Override
    public void serialize(ErrorDescriptor errorDescriptor, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        jsonGenerator.writeStartObject();
        jsonGenerator.writeFieldName(KEY_CODE);
        jsonGenerator.writeNumber(errorDescriptor.getCode());
        jsonGenerator.writeFieldName(KEY_DESCRIPTION);
        jsonGenerator.writeString(errorDescriptor.getDescription());
        jsonGenerator.writeEndObject();
    }
}
